/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package consumo.face.cadastro.impostos;

import consumo.entity.Concessionaria;
import consumo.entity.PisCofins;
import consumo.face.BaseCDIBean;
import consumo.session.ImpostosSesion;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;

/**
 *
 * @author Carlos Taschetto
 */

@ManagedBean
@ViewScoped
public class PisCofinsFace extends BaseCDIBean<PisCofins> {

    private static final long serialVersionUID = 1L;
    
    @Inject
    private ImpostosSesion bean;
    private List<PisCofins> lista;
    private boolean isNew;
    private List<Concessionaria> listaConce;
    


    @PostConstruct
    protected void init(){
        atribuiEstadoInicial();
    }

    private void atribuiEstadoInicial(){
        lista = null;
        listaConce = null;        
        setSelectedBean(new PisCofins());
    }

    
    /**
     * inicializa uma nova  a ser gravada
     */
    public void doCreate(){
        System.out.println("Entrou em create Icms");
        setIsNew(true);
        PisCofins pis = new PisCofins();
        pis.setConce(listaConce.get(0));
        pis.setMes(new Date());
        setSelectedBean(pis);
    }
    /**
     * Salva a 
     */
    private void doFinishCreate(){
        bean.save(getSelectedBean());
        lista = bean.getAllPisCofins();
    }

    /**
     * Edita uma 
     */
    private void doEdit(){
        bean.set(getSelectedBean());
        lista = bean.getAllPisCofins();
    }
    /**
     * Verifica se é uma nova inserção ou uma alteração
     */
    public void doSave(){
        if(isIsNew())
            doFinishCreate();
        else doEdit();
        setIsNew(false);

        //setSelectedIcm(null);
    }

    public List<PisCofins> getLista() {
        if(lista==null){
            lista = bean.getAllPisCofins();
        }
        return lista;
    }

    public void setLista(List<PisCofins> lista) {
        this.lista = lista;
    }

 
    public void doRemove(){
        bean.remove(getSelectedBean());
        System.out.println("doRemove");
        setLista(bean.getAllPisCofins());
    }

    public boolean isIsNew() {
        return isNew;
    }

    public void setIsNew(boolean isNew) {
        this.isNew = isNew;
    }

    public List<Concessionaria> getListaConce() {
        if(listaConce==null){
            listaConce = bean.getAllConcessionarias();
        }
        return listaConce;
    }

    public void setListaConce(List<Concessionaria> listaConce) {
        this.listaConce = listaConce;
    }
    
    public void resetIsNew(){
        this.isNew = false;
    }
}

